路径效果脚本(Path Effect Scripts)
路径效果脚本(Path Effect Scripts)可在运行时修改路径几何(Path Geometry),用于扭曲、变形、动画或程序化路径变换。
创建路径效果(Creating a Path Effect)
创建新脚本 并选择 路径效果(Path Effect) 类型。
示例(Examples)
脚本结构(Anatomy)
方法(Methods)
init(可选):初始化时调用一次update(必需):接收输入路径并返回更新后的路径advance(可选):每帧推进(适合时间驱动效果)
使用 PathData
PathData 提供 moveTo、lineTo、cubicTo、quadTo、close 等命令访问能力。可读取、重建或测量路径。
type MyPathEffect = {
context: Context,
}
function init(self: MyPathEffect, context: Context): boolean
self.context = context
return true
end
function update(self: MyPathEffect, inPath: PathData): PathData
local path = Path.new()
return path
end
function advance(self: MyPathEffect, seconds: number): boolean
return true
end
-- Return a factory function that Rive uses to build the Path Effect instance.
return function(): PathEffect<MyPathEffect>
return {
init = init,
update = update,
advance = advance,
context = late(),
}
end
将路径效果添加到描边
- 选择或新建一个形状描边
- 打开效果(Effects)页签并点击
+ - 在 Script Effects 中选择你的效果
- 若定义了输入(Inputs),可在此处编辑

添加输入
请参考 Script Inputs。